package com.itheima.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@EnableWebMvc // 启用springmvc框架 : springmvc容器
@ComponentScan("com.itheima.controller")
@Configuration // 声明配置类
public class SpringMvcConfig extends WebMvcConfigurationSupport {

    @Bean
    public InternalResourceViewResolver createInternalResourceViewResolver(){
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/pages/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

    /**
     * 对静态资源放行
     * @param defaultServlet
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer defaultServlet){
        defaultServlet.enable();
    }
}
